﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using CodeIn.Ui;
using CodeIn.Core.Modules;

namespace CodeIn.Modules.Ui.Edit {
	public class Edit : BaseModule {
		protected override void InitializeOverride() {
		}

		protected override bool CanExecuteOverride(string[] args) {
			if (args.Length < 2)
				return False("You must provide a valid file path as first argument");
			if (!File.Exists(args[1]))
				return False("File does not exist");
			return true;
		}

		protected override void ExecuteOverride(string[] args) {
			string path = args[1];
			string filename = Path.GetFileName(path);

			EditView view = null;
			var panel = UiHelper.CreateAndShowPanel(filename, PanelSide.MIDDLE, () => {
				view = new EditView();
				view.FilePath = path;
				return view;
			});

			UiHelper.Synchronize(() => { view.TabItemVmReference = panel; });
		}
	}
}
